const path = require('path')
const mkdirp = require('mkdirp')
const sd = require("silly-datetime")
const multer = require('multer')

const storage = multer.diskStorage({
    destination: async function (req, file, cb) {

        cb(null, './public/images')
    },
    filename: function (req, file, cb) {
        // 1. 获取文件后缀名
        let extName = path.extname(file.originalname)
        // 2. 根据时间戳生成文件名
        const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
        cb(null, file.fieldname + '-' + uniqueSuffix + extName)
    }
})
const uploader = multer({ storage: storage })

module.exports = uploader